﻿using Microsoft.AspNetCore.Http;
using PMS.Core.Utils;
using PMS.Data.Entities.Medias;

namespace PMS.Services.EntityServices.Medias
{
    public partial interface IMediaFileService
    {
        /// <summary>
        /// Returns the file extension from mime type.
        /// </summary>
        /// <param name="mimeType">Mime type</param>
        /// <returns>File extension</returns>
        string GetOutputFileExtensionFromMimeType(string mimeType);
        /// <summary>
        /// Returns the file extension from filename like: nopic.png
        /// Note: All Files Uploaded from client-side, should restore with filename and file extension
        /// eg: .jpeg or .jpg file all restore with extension name: .jpg 
        /// </summary>
        /// <param name="fileName">fileName and its extension name like: nopic.png</param>
        /// <returns></returns>
        string GetOutputFileExtensionFromFileName(string fileName);

        /// <summary>
        /// Gets the default Picture URL
        /// </summary>
        /// <param name="targetSize">The target picture size (longest side)</param>
        /// <returns>Picture URL</returns>
        string GetDefaultPictureUrl(int targetSize = 0);

        /// <summary>
        /// Get a Media File URL depends on media storage settings
        /// the default picture is shown when file not found
        /// </summary>
        /// <param name="fileId">Media file identifier</param>
        /// <param name="targetSize">The target picture size (longest side), only available when target is image type</param>
        /// <returns>
        /// Returns a ImageNotFound.jpg url as default url when media file not exists(deleted or unexpected situations)
        /// IsDefault : true, means target MediaFile not found(deleted or whatever), FileUrl is the default ImageFile Url(ImageNotFound.jpg) instead
        ///           : otherwise returns the target media file url
        /// </returns>
        (bool IsDefault, string FileUrl, string thumbFileUrl) GetMediaFileUrl(int fileId, int targetSize = 0);

        /// <summary>
        /// same as (bool IsDefault, string FileUrl) GetMediaFileUrl(int fileId, int targetSize = 0); 
        /// </summary>
        (bool IsDefault, string FileUrl, string thumbFileUrl) GetMediaFileUrl(ref MediaFile media, int targetSize = 0);

        /// <summary>
        /// Gets a MediaEntity
        /// </summary>
        /// <param name="fileId">Media file identifier</param>
        /// <returns>MediaFile</returns>
        MediaFile GetMediaFileById(int fileId);

        /// <summary>
        /// Deletes a MediaEntity
        /// </summary>
        /// <param name="file">MediaFile</param>
        bool DeleteMediaFile(MediaFile file);

        /// <summary>
        /// Gets a collection of media files
        /// </summary>
        /// <param name="pageIndex">Current page</param>
        /// <param name="pageSize">Items on each page</param>
        /// <returns>Paged list of media files</returns>
        IPagedList<MediaFile> GetMediaFiles(int pageIndex = 0, int pageSize = int.MaxValue);

        /// <summary>
        /// Gets the loaded picture binary only when MediaFile is Image
        /// depending on media storage settings
        /// </summary>
        /// <param name="imageFile">MediaFile</param>
        /// <returns>Picture binary</returns>
        byte[] LoadPictureBinary(MediaFile imageFile);
        /// <summary>
        /// Shortcut for insert a media file as Image
        /// Inserts a picture from pictureBinary, For scenario like base64 image
        /// </summary>
        /// <param name="pictureBinary">The picture binary</param>
        /// <param name="mimeType">The picture MIME type</param>
        /// <param name="useage">The useage of the image</param>
        /// <param name="title">"title" attribute for Image</param>
        /// <param name="description">"description" attribute for Image</param>
        /// <param name="imagelink">imagelink for image "href"</param>
        /// <returns>MediaFile</returns>
        MediaFile InsertPicture(byte[] pictureBinary, string mimeType, string useage = null,
            string title = null, string description = null, string imagelink = null);

        /// <summary>
        /// Shortcut for Updates a media file as Image
        /// Update a picture from pictureBinary, For scenario like base64 image
        /// </summary>
        /// <param name="pictureId">The picture identifier to be upload</param>
        /// <param name="mimeType">The input picture MIME type</param>
        /// <param name="pictureBinary">The input picture binary</param>
        /// <param name="useage">The useage of the image</param>
        /// <param name="title">"title" attribute for Image</param>
        /// <param name="description">"description" attribute for Image</param>
        /// <param name="imagelink">imagelink for image "href"</param>
        /// <returns>Picture</returns>
        MediaFile UpdatePicture(int pictureId, string mimeType, byte[] pictureBinary = null, string useage = null,
            string title = null, string description = null, string imagelink = null);

        /// <summary>
        /// Inserts a MediaFile
        /// </summary>
        /// <param name="formFile">Form file</param>
        /// <param name="useage">The useage of the MediaFile</param>
        /// <param name="title">"title" attribute for MediaFile</param>
        /// <param name="description">"description" attribute for MediaFile</param>
        /// <param name="imagelink">imagelink for image "href" if its a Image</param>
        /// <returns>MediaFile</returns>
        MediaFile InsertMediaFile(IFormFile formFile, string useage = null,
            string title = null, string description = null, string imagelink = null);

        /// <summary>
        /// Update a MediaFile
        /// </summary>
        /// <param name="fileId">The mediafile identifier</param>
        /// <param name="formFile">Form file</param>
        /// <param name="useage">The useage of the MediaFile</param>
        /// <param name="title">"title" attribute for MediaFile</param>
        /// <param name="description">"description" attribute for MediaFile</param>
        /// <param name="imagelink">imagelink for image "href" if its a Image</param>
        /// <returns>MediaFile</returns>
        MediaFile UpdateMediaFile(int fileId, IFormFile formFile, string useage = null,
            string title = null, string description = null, string imagelink = null);

        /// <summary>
        /// Updates the media file info only
        /// param for update: Id, Title, Description, Useage, ImageLink
        /// </summary>
        /// <param name="file">The MediaFile to update</param>
        /// <returns>Picture</returns>
        MediaFile UpdateMediaFileInfoOnly(MediaFile file);

    }
}
